﻿using Code;
using DB;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Models {
    public class SampleData {
        public async static Task InitDB() {
            using (var context = new SqlServerDB()) {
                if (context.Database != null && await context.Database.EnsureCreatedAsync()) {
                    Users users = new Users() {
                        UserCode = "admin",
                        UserName = "admin",
                        Password = "123123".MD5Encrypt64(),
                        UserType = UserTypes.超级管理员
                    };

                    await context.Users.AddAsync(users);

                    List<SystemSetting> list = new List<SystemSetting>();

                    list.Add(new SystemSetting {
                        SystemType = SystemType.提现,
                        OtherType = ((int)SystemType.提现手续费).ToString(),
                        Values = "2%"
                    });

                    #region 分红
                    #region SystemType.开发奖
                    list.Add(new SystemSetting {
                        SystemType = SystemType.开发奖,
                        OtherType = ((int)LevelCode.全国总代).ToString(),
                        Values = "695"
                    });

                    list.Add(new SystemSetting {
                        SystemType = SystemType.开发奖,
                        OtherType = ((int)LevelCode.省代).ToString(),
                        Values = "665"
                    });

                    list.Add(new SystemSetting {
                        SystemType = SystemType.开发奖,
                        OtherType = ((int)LevelCode.大区总代).ToString(),
                        Values = "620"
                    });

                    list.Add(new SystemSetting {
                        SystemType = SystemType.开发奖,
                        OtherType = ((int)LevelCode.市代).ToString(),
                        Values = "550"
                    });

                    list.Add(new SystemSetting {
                        SystemType = SystemType.开发奖,
                        OtherType = ((int)LevelCode.区代).ToString(),
                        Values = "465"
                    });

                    list.Add(new SystemSetting {
                        SystemType = SystemType.开发奖,
                        OtherType = ((int)LevelCode.批发商).ToString(),
                        Values = "355"
                    });

                    list.Add(new SystemSetting {
                        SystemType = SystemType.开发奖,
                        OtherType = ((int)LevelCode.代理).ToString(),
                        Values = "220"
                    });
                    #endregion

                    #region SystemType.团队分红
                    list.Add(new SystemSetting {
                        SystemType = SystemType.团队分红,
                        OtherType = ((int)LevelCode.全国总代).ToString(),
                        Values = "30"
                    });
                    list.Add(new SystemSetting {
                        SystemType = SystemType.团队分红,
                        OtherType = ((int)LevelCode.省代).ToString(),
                        Values = "45"
                    });
                    list.Add(new SystemSetting {
                        SystemType = SystemType.团队分红,
                        OtherType = ((int)LevelCode.大区总代).ToString(),
                        Values = "70"
                    });
                    list.Add(new SystemSetting {
                        SystemType = SystemType.团队分红,
                        OtherType = ((int)LevelCode.市代).ToString(),
                        Values = "85"
                    });
                    list.Add(new SystemSetting {
                        SystemType = SystemType.团队分红,
                        OtherType = ((int)LevelCode.区代).ToString(),
                        Values = "110"
                    });
                    list.Add(new SystemSetting {
                        SystemType = SystemType.团队分红,
                        OtherType = ((int)LevelCode.批发商).ToString(),
                        Values = "135"
                    });
                    list.Add(new SystemSetting {
                        SystemType = SystemType.团队分红,
                        OtherType = ((int)LevelCode.代理).ToString(),
                        Values = "0"
                    });
                    #endregion

                    #region SystemType.同级奖励
                    list.Add(new SystemSetting {
                        SystemType = SystemType.同级奖励,
                        OtherType = ((int)LevelCode.区代).ToString(),
                        Values = "10"
                    });

                    list.Add(new SystemSetting {
                        SystemType = SystemType.同级奖励,
                        OtherType = ((int)LevelCode.批发商).ToString(),
                        Values = "10"
                    });

                    list.Add(new SystemSetting {
                        SystemType = SystemType.同级奖励,
                        OtherType = ((int)SystemType.同级奖励分配人数).ToString(),
                        Values = "5"
                    });
                    #endregion


                    list.Add(new SystemSetting {
                        SystemType = SystemType.城市管理,
                        OtherType = ((int)LevelCode.市代).ToString(),
                        Values = "20"
                    });


                    list.Add(new SystemSetting {
                        SystemType = SystemType.大区分红,
                        OtherType = ((int)LevelCode.大区总代).ToString(),
                        Values = "10"
                    });
                    list.Add(new SystemSetting {
                        SystemType = SystemType.大区分红,
                        OtherType = ((int)SystemType.大区分红人数未满).ToString(),
                        Values = "5"
                    });


                    list.Add(new SystemSetting {
                        SystemType = SystemType.省级分红,
                        OtherType = ((int)LevelCode.省代).ToString(),
                        Values = "6"
                    });

                    list.Add(new SystemSetting {
                        SystemType = SystemType.终身分红,
                        OtherType = ((int)LevelCode.全国总代).ToString(),
                        Values = "20"
                    });

                    #region 感恩分红
                    list.Add(new SystemSetting {
                        SystemType = SystemType.感恩分红,
                        OtherType = ((int)SystemType.永久奖励).ToString(),
                        Values = "2"
                    });

                    list.Add(new SystemSetting {
                        SystemType = SystemType.感恩分红,
                        OtherType = ((int)LevelCode.全国总代).ToString(),
                        Values = "60%"
                    });

                    list.Add(new SystemSetting {
                        SystemType = SystemType.感恩分红,
                        OtherType = ((int)LevelCode.省代).ToString(),
                        Values = "50%"
                    });

                    list.Add(new SystemSetting {
                        SystemType = SystemType.感恩分红,
                        OtherType = ((int)LevelCode.大区总代).ToString(),
                        Values = "40%"
                    });

                    list.Add(new SystemSetting {
                        SystemType = SystemType.感恩分红,
                        OtherType = ((int)LevelCode.市代).ToString(),
                        Values = "30%"
                    });

                    list.Add(new SystemSetting {
                        SystemType = SystemType.感恩分红,
                        OtherType = ((int)SystemType.感恩分红最大天数).ToString(),
                        Values = "10"
                    });
                    #endregion
                    #endregion

                    #region 升级
                    //list.Add(new SystemSetting {
                    //    SystemType = SystemType.升级条件,
                    //    OtherType = ((int)LevelCode.全国总代).ToString(),
                    //    Values = "2"
                    //});

                    list.Add(new SystemSetting {
                        SystemType = SystemType.升级条件,
                        OtherType = ((int)LevelCode.省代).ToString(),
                        Values = "2"
                    });

                    list.Add(new SystemSetting {
                        SystemType = SystemType.升级条件,
                        OtherType = ((int)LevelCode.大区总代).ToString(),
                        Values = "3"
                    });

                    list.Add(new SystemSetting {
                        SystemType = SystemType.升级条件,
                        OtherType = ((int)LevelCode.市代).ToString(),
                        Values = "4"
                    });

                    list.Add(new SystemSetting {
                        SystemType = SystemType.升级条件,
                        OtherType = ((int)LevelCode.区代).ToString(),
                        Values = "4"
                    });

                    list.Add(new SystemSetting {
                        SystemType = SystemType.升级条件,
                        OtherType = ((int)LevelCode.批发商).ToString(),
                        Values = "6"
                    });

                    list.Add(new SystemSetting {
                        SystemType = SystemType.升级条件,
                        OtherType = ((int)LevelCode.代理).ToString(),
                        Values = "9"
                    });
                    list.Add(new SystemSetting {
                        SystemType = SystemType.升级条件,
                        OtherType = ((int)LevelCode.未激活).ToString(),
                        Values = "1520"
                    });

                    #endregion

                    await context.Notices.AddAsync(new Notice {
                        NoticeType = NoticeType.购买协议,
                        Name = "益健橘红茶",
                        CreateTime = DateTime.Now
                    });

                    await context.Settings.AddRangeAsync(new List<SystemSetting> {
                        new SystemSetting{
                            SystemType = SystemType.收款信息,
                            OtherType = ((int)SystemType.收款人).ToString(),
                            Values = "柯宏伟"
                        },
                        new SystemSetting{
                            SystemType = SystemType.收款信息,
                            OtherType = ((int)SystemType.收款账号).ToString(),
                            Values = "6227003145010076415"
                        },
                        new SystemSetting{
                            SystemType = SystemType.收款信息,
                            OtherType = ((int)SystemType.收款银行).ToString(),
                            Values = "中国建设银行广东省分行茂名市西粤南分理处"
                        },
                        new SystemSetting{
                            SystemType = SystemType.提现,
                            OtherType = ((int)SystemType.提现日期).ToString(),
                            Values = "5,15,25"
                        },
                    });

                    await context.Settings.AddRangeAsync(list);

                    await context.SaveChangesAsync();
                }
            }
        }
    }
}
